package com.example.thread.d9CompletableFuture2.d3异步任务回调;

import com.example.thread.d9CompletableFuture2.CommonUtils;

import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class D4ThenApplyAsyncDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CommonUtils.printThreadLog("main start");

        CompletableFuture<String[]> future = CompletableFuture.supplyAsync(() -> {
            CommonUtils.printThreadLog("读取文件开始");
            String s = CommonUtils.readFile("读取,文件");
            return s;
        }).thenApplyAsync(content -> {
            CommonUtils.printThreadLog("打印输出");
            String[] contents = content.split(",");
            return contents;
        });

        CommonUtils.printThreadLog("main continue");
        String[] strings = future.get();
        CommonUtils.printThreadLog("打印。。"+ Arrays.toString(strings));
        CommonUtils.printThreadLog("main end");
    }
}
